package com.QK.cnstudy;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.QK.cnstudy.db.DBManager;
import com.QK.cnstudy.entity.Word;
import com.QK.cnstudy.entity.Work;

public class WordActivity extends Activity implements OnClickListener {

    private int workId;
    private TextView titleTextView;
    private TextView contentTextView;
    private DBManager dbManager;
    private String titleString;
    private String contentString;

    Button backButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.word);
        getView();
        Bundle bundle = getIntent().getExtras();
        dbManager = CnStudyApp.app.dbManager;
        workId = bundle.getInt("id");
        Work work = dbManager.getWorkById(workId);
        titleString = work.getName();
        contentString = "";
        List<Word> words = dbManager.getWords(work.getId());
        for (Word word : words) {
            contentString += "<font color='#63950c'>" + word.getContent() + "：</font>" + word.getTranslation()
                            + "<br/>";
        }
//        contentString += "<br/><br/><br/>";
        titleTextView.setText(titleString);
        contentTextView.setText(Html.fromHtml(contentString));
        backButton.setOnClickListener(this);
    }

    public void getView() {
        titleTextView = (TextView) findViewById(R.id.state);
        contentTextView = (TextView) findViewById(R.id.content);
        backButton = (Button) findViewById(R.id.back);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.back:
            onBackPressed();
            break;

        default:
            break;
        }

    }
}
